home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 March: Reference Library / Dev.CD Mar 96 RL / Dev.CD Mar 96 RL.toast / Technical Documentation / develop / develop Issue 25 / develop Issue 25 code / Display Manager Sample / Source / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-19  |  3.1 KB  |  155 lines  |  [TEXT/MPCC]

  1. /***********************************************************************
  2. #
  3. #        main.c
  4. #
  5. #        This is the main entry point.
  6. #
  7. #        Author: Michael Marinkovich
  8. #                Apple Developer Technical Support
  9. #
  10. #
  11. #        Modification History: 
  12. #
  13. #            6/4/95        MWM     Initial coding                     
  14. #            10/12/95    MWM        cleaned up
  15. #
  16. #        Copyright © 1992-95 Apple Computer, Inc., All Rights Reserved
  17. #
  18. #
  19. ***********************************************************************/
  20.  
  21.  
  22. #include <ToolUtils.h>
  23.  
  24. #include "App.h"
  25. #include "Global.h"
  26. #include "Proto.h"
  27.  
  28.  
  29. // declare QuickDraw globals if not
  30. // building with MetroWorks
  31. #ifdef powerc            
  32. #ifndef __MWERKS__
  33.     QDGlobals qd;
  34. #endif
  35. #endif
  36.  
  37.  
  38.  
  39. //----------------------------------------------------------------------
  40. //
  41. //    main - main entry point of our program
  42. //
  43. //
  44. //----------------------------------------------------------------------
  45.  
  46. void main(void)
  47. {
  48.     OSErr            err;
  49.     long            total, contig;
  50.     short            m = 5;
  51.         
  52.     MaxApplZone();
  53.     
  54.     for (;m == 0;m--)                 // alloc the master pointers
  55.         MoreMasters();
  56.  
  57.     if ((long)GetApplLimit() - (long)ApplicationZone() < kMinHeap)
  58.             HandleError( MemError(), true );
  59.  
  60.     PurgeSpace(&total, &contig);
  61.     if (total < kMinSpace)
  62.             HandleError( MemError(), true );
  63.         
  64.     err = Initialize();
  65.     
  66.     EventLoop();        
  67.     ExitToShell();
  68.     (void) RemoveDMNotification();
  69.  
  70. }
  71.  
  72.  
  73. //----------------------------------------------------------------------
  74. //
  75. //    HandleError - basic error notification procedure
  76. //
  77. //
  78. //----------------------------------------------------------------------
  79.  
  80. void HandleError(short errNo,Boolean fatal)
  81. {
  82.     DialogPtr            errDialog;
  83.     short                itemHit;
  84.     short                c;
  85.     Handle                button;
  86.     short                itemType;
  87.     Rect                itemRect;
  88.     StringHandle        errString;
  89.     Str255                numString;
  90.     GrafPtr                oldPort;
  91.     
  92.     GetPort(&oldPort);
  93.     SysBeep(30);
  94.     SetCursor(&qd.arrow);
  95.     
  96.     errDialog = GetNewDialog(rErrorDlg, nil, (WindowPtr) -1);
  97.     if (errDialog != nil) {
  98.         ShowWindow(errDialog);
  99.         SetPort(errDialog);
  100.         
  101.         PenPat(&qd.gray);                                // frame user areas
  102.         for (c = 7;c < 9;c++) {
  103.             GetDItem(errDialog,c,&itemType,&button,&itemRect);
  104.             FrameRect(&itemRect);
  105.         }
  106.         PenPat(normal);
  107.  
  108.         GetDItem( errDialog, fatal ? 2 : 1, &itemType, &button, &itemRect );
  109.         HiliteControl( (ControlHandle)button, 255);         //    unhilite appropriate button
  110.         
  111.         SetDialogDefaultItem(errDialog,fatal  ? 1 : 2);
  112.         
  113.         NumToString( errNo, numString );
  114.         if ( errNo < 0 )
  115.             errNo = -errNo + 200;
  116.         errString = GetString( 128 + errNo );
  117.         if ( errString == nil )
  118.                 errString = GetString( 128 );
  119.         HLock((Handle)errString);
  120.         
  121.         ParamText( numString, *errString, nil, nil );
  122.     
  123.         HUnlock((Handle)errString);
  124.         
  125.         ModalDialog( nil, &itemHit );
  126.         
  127.         SetPort( oldPort );
  128.  
  129.         DisposeWindow( errDialog );
  130.     }
  131.     else
  132.         ExitToShell();        // since didn't have mem to open dialog assume the worst
  133.             
  134.     if (fatal) 
  135.         ExitToShell();        //    it's a bad one, get out of here
  136.     
  137. }
  138.  
  139.  
  140. //----------------------------------------------------------------------
  141. //
  142. //    HandleAlert - display alert and then exit to shell
  143. //
  144. //
  145. //----------------------------------------------------------------------
  146.  
  147. void HandleAlert(short alertID)
  148. {
  149.     short            item;
  150.     
  151.     
  152.     item = Alert(alertID,nil);
  153.     ExitToShell();
  154.  
  155. }